package com.example.datn.activities;

import java.util.ArrayList;

import com.example.datn.MainActivity;
import com.example.datn.R;
import com.example.datn.adapter.SingerItemAdapter;
import com.example.datn.manager.AlbumManager;
import com.example.datn.manager.SingerManager;
import com.example.datn.manager.SongManager;
import com.example.datn.manager.VideoManager;
import com.example.datn.objects.SingerOject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

public class ViewGridSingers extends Activity implements OnItemClickListener{

	ArrayList<SingerOject> listSinger;
	GridView gridSingers;
	SingerOject singer;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.grid_singers);
		gridSingers = (GridView)findViewById(R.id.grid_singer);
		
		listSinger = SingerManager.getInstance().getListSinger();
		if(listSinger.size() ==  0)
			initListSinger();
		
		SingerItemAdapter myAdapter = new SingerItemAdapter(this, R.layout.my_singer_item, listSinger);
		gridSingers.setAdapter(myAdapter);
		gridSingers.setOnItemClickListener(this);
	}

	private void initListSinger() {
		listSinger = new ArrayList<SingerOject>();
		
		//-----------------------------------------
		singer = new SingerOject(1, "Quang Lê", R.string.quangle_profile, R.drawable.imgquangle1);
		singer.listLinkSong = new String[]{
				"http://mp3.zing.vn/nghe-si/Quang-Le/bai-hat",
				"http://mp3.zing.vn/nghe-si/Quang-Le/bai-hat?p=2",
				"http://mp3.zing.vn/nghe-si/Quang-Le/bai-hat?p=3"};
		singer.linkGetAlbum = "http://mp3.zing.vn/nghe-si/Quang-Le/album";
		listSinger.add(singer);
		
		//-----------------------------------------
		singer = new SingerOject(2, "Trọng Tấn", R.string.trongtan_profile, R.drawable.img_trongtan_avatar);
		singer.listLinkSong = new String[]{
				"http://mp3.zing.vn/nghe-si/Trong-Tan/bai-hat",
				"http://mp3.zing.vn/nghe-si/Trong-Tan/bai-hat?p=2",
				"http://mp3.zing.vn/nghe-si/Trong-Tan/bai-hat?p=3",
				"http://mp3.zing.vn/nghe-si/Trong-Tan/bai-hat?p=4"};
		singer.linkGetAlbum = "http://mp3.zing.vn/nghe-si/Trong-Tan/album";
		listSinger.add(singer);
		
		//-----------------------------------------
		singer = new SingerOject(3, "Mai Thiên Vân", R.string.maithienvan_profile, R.drawable.img_maithienvan_avatar);
		singer.listLinkSong = new String[]{
				"http://mp3.zing.vn/nghe-si/Mai-Thien-Van/bai-hat",
				"http://mp3.zing.vn/nghe-si/Mai-Thien-Van/bai-hat?p=2",
				"http://mp3.zing.vn/nghe-si/Mai-Thien-Van/bai-hat?p=3"};
		singer.linkGetAlbum = "http://mp3.zing.vn/nghe-si/Mai-Thien-Van/album";
		listSinger.add(singer);
		

		//-----------------------------------------
		singer = new SingerOject(4, "Ái Vân", R.string.aivan_profile, R.drawable.img_aivan_avatar);
		singer.listLinkSong = new String[]{
				"http://mp3.zing.vn/nghe-si/Ai-Van/bai-hat",
				"http://mp3.zing.vn/nghe-si/Ai-Van/bai-hat?p=2",
				"http://mp3.zing.vn/nghe-si/Ai-Van/bai-hat?p=3"};
		singer.linkGetAlbum = "http://mp3.zing.vn/nghe-si/Ai-Van/album";
		listSinger.add(singer);
 
		//-----------------------------------------
		singer = new SingerOject(5, "Như Quỳnh", R.string.nhuquynh_profile, R.drawable.img_nhuquynh_avatar);
		singer.listLinkSong = new String[]{
				"http://mp3.zing.vn/nghe-si/Nhu-Quynh/bai-hat",
				"http://mp3.zing.vn/nghe-si/Nhu-Quynh/bai-hat?p=2",
				"http://mp3.zing.vn/nghe-si/Nhu-Quynh/bai-hat?p=3"};
		singer.linkGetAlbum = "http://mp3.zing.vn/nghe-si/Nhu-Quynh/album";
		listSinger.add(singer);
		
		//------------------------------------------
		singer = new SingerOject(6, "Dương Triệu Vũ", R.string.duongtrieuvu_profile, R.drawable.img_trieuvu_avatar);
		singer.listLinkSong = new String[]{
				"http://mp3.zing.vn/nghe-si/Duong-Trieu-Vu/bai-hat",
				"http://mp3.zing.vn/nghe-si/Duong-Trieu-Vu/bai-hat?p=2",
				"http://mp3.zing.vn/nghe-si/Duong-Trieu-Vu/bai-hat?p=3"};
		singer.linkGetAlbum = "http://mp3.zing.vn/nghe-si/Duong-Trieu-Vu/album";
		listSinger.add(singer);

		
		SingerManager.getInstance().setListSinger(listSinger);		
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View v, int id, long arg3) {
		SingerOject singer = SingerManager.getInstance().getListSinger().get(id);
		SingerManager.getInstance().setCurrentSinger(singer);
		refreshApp();
		Intent i = new Intent(this, MainActivity.class);
		startActivity(i);	
			
	}

	private void refreshApp(){
		SongManager.getInstance().release();
		AlbumManager.getInstance().release();
		VideoManager.getInstance().release();
	}
	
}
